package com.sisyphe.android.srouter.spi.b

import android.util.Log
import com.sisyphe.android.srouter.facade.SRouter
import com.sisyphe.android.srouter.facade.annotation.Autowired
import com.sisyphe.android.srouter.spi.base.LoginProvider

class LoginInvoke {

    @Autowired(name = "/user/loginInject")
    lateinit var provider: LoginProvider

    init {
        SRouter.inject(this)
//        provider = IProvider::class.java.getDeclaredConstructor().newInstance()
//        provider = Class.forName("com.sisyphe.android.srouter.spi.a.LoginInject").getDeclaredConstructor().newInstance() as LoginProvider
    }

    fun login() {
        val result = provider.login("", "")
        Log.d("TAG", "is auto login: $result")
//        Proxy.newProxyInstance(IProvider::class.java.classLoader, arrayOf(IProvider::class.java), ProxyHandler(provider))
//        val loader = ServiceLoader.load(IProvider::class.java)
//        val iterator = loader.iterator()
//        while (iterator.hasNext()) {
//            val provider = iterator.next()
//            provider.login()
//        }
    }

//    class ProxyHandler(private val provider: IProvider) : InvocationHandler {
//
//        override fun invoke(proxy: Any?, method: Method?, args: Array<out Any>?): Any? {
//            val invoke = method?.invoke(provider)
//            return invoke
//        }
//    }
}